package com.solace.selenium;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;

import java.io.File;

public class HelloWorld extends Application {

   @Override
   public void start(Stage primaryStage) {
       //容器的根节点设置为边缘布局
       BorderPane root = new BorderPane();

       //水平布局
       HBox hbox = new HBox();
       //设置hbox布局方式为居中
       hbox.setAlignment(Pos.CENTER);
       //padding属性可设置为管理节点与HBox窗格边缘之间的距离,分别是上，右，下，左
       hbox.setPadding(new Insets(20,10,20,10));
       //设置节点之间的间距，这里设置的是TextField、Button之间水平间距
       hbox.setSpacing(2);
       //设置背景颜色
       hbox.setStyle("-fx-background-color: #336699;");

       TextField textField = new TextField();
       Button selectButton = new Button("选择文件");
       selectButton.setOnAction(new EventHandler<ActionEvent>() {
           @Override
           public void handle(ActionEvent event) {
               DirectoryChooser dc = new DirectoryChooser();
               dc.setInitialDirectory(new File("D:" + File.separator));
               File file = dc.showDialog(primaryStage);
               String path = file.getPath();
               System.out.println("选择的文件夹:"+path);
               textField.setText(path);
           }
       });

       //清除页面星号
       Button clearAsterisk = new Button("清除星号");

       Button exportOrder = new Button("导出订单");
       hbox.getChildren().addAll(textField,selectButton,clearAsterisk,exportOrder);

       //Hgrow是 horizontal grow缩写意为水平增长，在这里是水平增长沾满窗口
       HBox.setHgrow(textField, Priority.ALWAYS);

       //将hbox布局容器放入BorderPane布局容器中
       root.setTop(hbox);
       //创建场景
       Scene scene = new Scene(root, 500, 70);
       primaryStage.setScene(scene);
//       scene.getStylesheets().add(HelloWorld.class.getResource("img.css").toExternalForm());
       //设置标题
       primaryStage.setTitle("订单下载工具");
       //打开窗口
       primaryStage.show();

   }

   public static void main(String[] args) {
       launch(args);
   }
}